#include<iostream>
using namespace std;

template <class T>//模板类
class Array{
    private:
       T* data;//存储数据
       int size;//元素的个数
       int capacity;//表示实际容量

    public:
        Array():data(NULL),size(0),capacity(0){}
        ~Array(){ 
            delete [] data;
            data=NULL;
            size=capacity=0;
        }
        Array(const Array& arr){
            size=arr.size;
            capacity=arr.capacity;
            data=new T[capacity];
            for(int i=0;i<size;i++){
                data[i]=arr.data[i];
            }
        }

        void push_back(const T da){
            if(capacity==0) {
                capacity += 1;
                data = new T[capacity];
            } else if(size > capacity){
                //当超出范围时，capacity倍增
                capacity *=2;
                T* temp = new T[capacity];
                for(int i=0; i<size; ++i){
                    temp[i] = data[i];
                }
                delete [] data;
                data = temp;
            }
            data[size] = da;
            ++size;
    }

    void pop_back(int nm){
        if(nm<=0&&nm>size){
            cout<<"你要删除的数据项有误，请仔细检查"<<endl;
        }
        else{
            for(int i=nm;i<size;i++){
                data[i-1]=data[i];        
            }
            size--;
        }
    }

    int getsize(){
        return size;
    }

    int getcapacity(){
        return capacity;
    }

    void showdata(int num){
        if(num<=size){
            cout<<"第"<<num<<"位存储的数据为："<<data[num-1]<<endl;
        }
        else{
            cout<<"你输入的数据超出size的范围"<<endl;
        }

    }


};

int main(){
    
    Array<int> a;
    //push数据
    a.push_back(1);
    a.push_back(2);
    a.push_back(3);
    cout<<"存储的数据的个数为"<<a.getsize()<<endl;
    a.showdata(2);
    a.pop_back(2);
    cout<<"已删除第2位存储数据"<<endl;
    cout<<"现在存储的个数为："<<a.getsize()<<endl;
    a.showdata(2);
    

}